package com.zoo.diannaopeijian.controller.component;

import com.zoo.diannaopeijian.comm.filter.FilterUtil;
import com.zoo.diannaopeijian.comm.logger.LoggerManage;
import com.zoo.diannaopeijian.comm.page.Page;
import com.zoo.diannaopeijian.controller.BaseController;
import com.zoo.diannaopeijian.domain.Component;
import com.zoo.diannaopeijian.service.ComponentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zx583 on 2018-01-15.
 */
@Controller
@RequestMapping("/component")
public class ComponentController extends BaseController {
    @Resource
    private ComponentService componentService;

    @RequestMapping("/componentManaPage")
    @LoggerManage(description = "访问标签管理页面")
    public String componentRoute() {
        return "component/componentManaPage";
    }

    @RequestMapping("/getComponent")
    @ResponseBody
    public List<Component> getComponent() {
        return componentService.getComponent(null);
    }

    @RequestMapping("/getFilterComponent")
    @ResponseBody
    public List getFilterComponent() {
        return FilterUtil.getFilterData(componentService.getComponent(null), "componentid", "componentname");
    }

    @RequestMapping("/addComponent")
    @ResponseBody
    public String addComponent(Component component) {
        return componentService.addComponent(component) ? success : fail;
    }

    @RequestMapping("/deleteComponent")
    @ResponseBody
    public String deleteComponent(Integer componentid) {
        return componentService.deleteComponent(componentid) ? success : fail;
    }

    @RequestMapping("/updateComponent")
    @ResponseBody
    public String updateComponent(Component component) {
        return componentService.updateComponent(component) ? success : fail;
    }
}
